﻿using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apple.DAL
{
    public static class DB
    {
        public static ISqlSugarClient SqlSugarClient { get; set; }

        public static void AddSqlSugarSetup(this IServiceCollection services, string connectionString, DbType dbType = DbType.Sqlite)
        {
            services.AddSingleton<ISqlSugarClient>(s =>
            {
                SqlSugarClient = new SqlSugarScope(new ConnectionConfig()
                {
                    DbType = dbType,
                    ConnectionString = connectionString,
                    IsAutoCloseConnection = true,
                    InitKeyType = InitKeyType.Attribute
                });

                return SqlSugarClient;
            });
        }
    }
}
